﻿using Humanizer;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Sheep_Breeding.Domain;
using Sheep_Breeding.ErrorCode;
using Sheep_Breeding.Read.Api.DTOSheep;
using Sheep_Breeding.Read.Api.OperationServices.IServices;

namespace Sheep_Breeding.Read.Api.Controllers
{

    /// <summary>
    /// 羊场管理控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SheepfarmController : ControllerBase
    {
        private readonly ILogger<SheepfarmController> logger;
        private readonly ISheepfarmServices sheepfarmServices;

        public SheepfarmController(ILogger<SheepfarmController> logger, ISheepfarmServices sheepfarmServices)
        {
            this.logger = logger;
            this.sheepfarmServices = sheepfarmServices;
        }

        /// <summary>
        /// 查找羊场规模数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<Thescalethsheepfarm>>> SearchSheepFiles()
        {
            try
            {
                return await sheepfarmServices.SearchSheepFiles();
            }
            catch (Exception ex)
            {

                logger.LogError("=>" + ex.Message);
                throw ex;
            }
        }

        /// <summary>
        /// 获取羊场管理数据
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public async Task<ApiPaging<List<Sheepfarm_managementDto>>> SearchSheepfarm_management([FromQuery] SearchSheepfarm_managementQueryDto dto)
        {
            try
            {
                return await sheepfarmServices.SearchSheepfarm_management(dto);
            }
            catch (Exception ex)
            {

                logger.LogError("=>" + ex.Message);
                throw ex;
            }
        }

        /// <summary>
        /// 查找栋舍类型
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<House_typeInfo>>> SearchHouse_typeInfo()
        {
            try
            {
                return await sheepfarmServices.SearchHouse_typeInfo();
            }
            catch (Exception ex)
            {

                logger.LogError("=>" + ex.Message);
                throw ex;
            }
        }

        /// <summary>
        /// 查找栋舍管理信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiPaging<List<SearchforbuildinginfoDto>>> SearchBuildingManagement([FromQuery]SearchBuildingManagementDto dto)
        {
            try
            {
                return await sheepfarmServices.SearchBuildingManagement(dto);
            }
            catch (Exception ex)
            {

                logger.LogError("=>" + ex.Message);
                throw ex;
            }
        }

        /// <summary>
        /// 根据栋舍Id查找栏位管理信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public async Task<ApiPaging<List<Field_management>>> SearchField_management([FromQuery]SearchField_managementDto dto)
        {
            try
            {
                return await sheepfarmServices.SearchField_management(dto);
            }
            catch (Exception ex)
            {

                logger.LogError("=>" + ex.Message);
                throw ex;
            }
        }
    }
}
